/*
package com.wzdigit.wms.raw.service.gdn;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzdigit.framework.Shift;
import com.wzdigit.framework.utils.RedisUtil;
import com.wzdigit.mes.basic.api.BasicSimpleCodeRuleApi;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.basic.domain.dtos.inventory.UpdateInventoryInputDto;
import com.wzdigit.wms.basic.domain.inventory.Goods;
import com.wzdigit.wms.basic.domain.inventory.GoodsHis;
import com.wzdigit.wms.basic.domain.inventory.GoodsLog;
import com.wzdigit.wms.basic.domain.order.TrsnDtl;
import com.wzdigit.wms.basic.domain.order.TrsnHeader;
import com.wzdigit.wms.basic.domain.transfer.GdnHeader;
import com.wzdigit.wms.basic.enums.*;
import com.wzdigit.wms.basic.mapper.core.inventory.GoodsHisMapper;
import com.wzdigit.wms.basic.mapper.core.inventory.GoodsLogMapper;
import com.wzdigit.wms.basic.mapper.core.inventory.GoodsMapper;
import com.wzdigit.wms.basic.mapper.core.order.TrsnDtlMapper;
import com.wzdigit.wms.basic.mapper.core.order.TrsnHeaderMapper;
import com.wzdigit.wms.basic.mapper.core.transfer.GdnHeaderMapper;
import com.wzdigit.wms.basic.service.code.InventoryService;
import com.wzdigit.wms.basic.util.HttpSessionUtil;
import com.wzdigit.wms.raw.client.response.gdn.delivery.*;
import com.wzdigit.wms.raw.mapper.gdn.DeliveryMapper;
import lombok.extern.slf4j.Slf4j;
import net.dreamlu.mica.core.utils.BeanUtil;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

*
 *
 * 交接确认PDA
 * 缓存信息：主页明细框&对应SN集合信息
 * Created by zyf on 2021/7/8 10:05


@Service
@Slf4j
public class DeliveryService {
    private static final String DTL="dtl";
    private static final String SN="sn";
    private static final String TRSN_ORDER = "TRSN_ORDER";

    @Autowired
    private DeliveryMapper deliveryMapper;
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private GdnHeaderMapper gdnHeaderMapper;
    @Lazy
    @Autowired
    private TrsnHeaderMapper trsnHeaderMapper;
    @Lazy
    @Autowired
    private TrsnDtlMapper trsnDtlMapper;
    @Lazy
    @Autowired
    private GoodsHisMapper goodsHisMapper;
    @Lazy
    @Autowired
    private GoodsLogMapper goodsLogMapper;


    @Reference(version = "${dubbo.consumers.basic.simple.code.rule.api:1.0.0}", check = false)
    private BasicSimpleCodeRuleApi basicSimpleCodeRuleApi;

    @Lazy
    @Autowired
    private InventoryService inventoryService;


        交接确认提交功能：前段验证扫描数是否与订单数相等
        1.发货单头状态为0(取消)或4(已完成)或5(已关闭)，报错
        2.根据gdnNo获取缓存的要交接确认的SN信息
        3.发货单所有明细的状态0(取消)或7(已发运)或8(已关闭)，报错
        4.交接功能
            （1）生成入库凭证单头
            （2）生成入库单明细
            （3）更新库位库存&库区库存
            （4）写SN操作日志
            （5）将SN从GOODS表删除移到GOODS_HIS表【置空WHS_ID&LOC_ID】
            （6）更新发货单主档状态为4(已完成)
            （7）更新发货单明细的发货数为订单数，状态为4(已完成)
            （8）更新发货单货品状态为2(已出库)
            （9）清除缓存


    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public Result<?> deliveryCommit(String gdnNo, BigDecimal gdnHeaderId,
                                    HttpServletRequest servletRequest, HttpServletResponse servletResponse)
    throws Exception{
        SimpleGdnHeader gdnHeader = deliveryMapper.searchGdnHeader(gdnNo);
        if (gdnHeader==null){
            Shift.fatal("请选择正确的出库单!");
        }
        if (gdnHeader.getStatus()==null){
            Shift.fatal("出库单["+gdnNo+"]状态错误,不可进行出库交接确认!");
        }
        if (gdnHeader.getStatus().equals(GdnHeaderStatusEnum.CANCEL.code)){
            Shift.fatal("出库单["+gdnNo+"]状态为["+GdnHeaderStatusEnum.CANCEL.enumName+"],不可进行出库交接确认!");
        }
        if (gdnHeader.getStatus().equals(GdnHeaderStatusEnum.FINISH.code)){
            Shift.fatal("出库单["+gdnNo+"]状态为["+GdnHeaderStatusEnum.FINISH.enumName+"],不可进行出库交接确认!");
        }
        if (gdnHeader.getStatus().equals(GdnHeaderStatusEnum.CLOSE.code)){
            Shift.fatal("出库单["+gdnNo+"]状态为["+GdnHeaderStatusEnum.CLOSE.enumName+"],不可进行出库交接确认!");
        }
        //查询出库明细信息
        List<SimpleGdnDtl> gdnDtls = deliveryMapper.selectGdnDtlList(gdnHeaderId);
        for (SimpleGdnDtl gdnDtl : gdnDtls) {
            if (gdnDtl.getStatus()==null){
                Shift.fatal("出库单["+gdnNo+"]明细行号["+gdnDtl.getGdnLineNo()+"]、料号["+gdnDtl.getSkuCode()
                        +"]状态错误，不可进行交接确认!");
            }
            if (gdnDtl.getStatus().equals(GdnDtlStatusEnum.CANCEL.code)){
                Shift.fatal("出库单["+gdnNo+"]明细行号["+gdnDtl.getGdnLineNo()+"]、料号["+gdnDtl.getSkuCode()
                        +"]状态为["+GdnDtlStatusEnum.CANCEL.enumName+"]，不可进行交接确认!");
            }
            if (gdnDtl.getStatus().equals(GdnDtlStatusEnum.SHIPMENTED.code)){
                Shift.fatal("出库单["+gdnNo+"]明细行号["+gdnDtl.getGdnLineNo()+"]、料号["+gdnDtl.getSkuCode()
                        +"]状态为["+GdnDtlStatusEnum.SHIPMENTED.enumName+"]，不可进行交接确认!");
            }
            if (gdnDtl.getStatus().equals(GdnDtlStatusEnum.CLOSE.code)){
                Shift.fatal("出库单["+gdnNo+"]明细行号["+gdnDtl.getGdnLineNo()+"]、料号["+gdnDtl.getSkuCode()
                        +"]状态为["+GdnDtlStatusEnum.CLOSE.enumName+"]，不可进行交接确认!");
            }
        }
        String loginName = HttpSessionUtil.getLoginName(servletRequest);
        //不直接用缓存的数据，怕出错

        //查询对应发货单下的货品
        List<DeliveryGoodsResponse> gdnDtlGoodsList =
                deliveryMapper.selectDeliveryGoods(gdnHeaderId, null);

        //发货单下全部的SN信息
        List<String> goodsSnList
                = gdnDtlGoodsList.stream().map(t -> t.getGoodsSn()).collect(Collectors.toList());
        //全部SN已扫描才能出库
        List<DeliveryGoodsResponse> goodsCacheList = getGoodsListCache(gdnNo);
        if (CollectionUtil.isEmpty(goodsCacheList)){
            Shift.fatal("扫描数小于需求数，不可出库!");
        }
        List<String> cacheSnList = goodsCacheList.stream().map(t -> t.getGoodsSn()).collect(Collectors.toList());
        for (String goodsSn : goodsSnList) {
            if (!cacheSnList.contains(goodsSn)){
                Shift.fatal("["+goodsSn+"]未扫描，不可出库!");
            }
        }

        QueryWrapper<Goods> goodsQueryWrapper=new QueryWrapper<>();
        goodsQueryWrapper.in("GOODS_SN",goodsSnList);
        List<Goods> goodsList = goodsMapper.selectList(goodsQueryWrapper);
        //记录入库凭证
        TrsnHeader trsnHeader = this.setTrsnHeader(gdnHeader, gdnDtls.get(0), loginName);
        trsnHeaderMapper.insert(trsnHeader);
        List<TrsnDtl> trsnDtls = this.setTrsnDtlList(gdnHeader, gdnDtls, loginName, trsnHeader);
        for (TrsnDtl trsnDtl : trsnDtls) {
            trsnDtlMapper.insert(trsnDtl);
        }
        Date logDate = new Date();
        for (Goods goods : goodsList) {
            //减少库存
            UpdateInventoryInputDto dto = this.setInventoryInputDto(goods, loginName);
            inventoryService.updateLocInventroy(dto);
            inventoryService.updateZoneInventory(dto);
            //写SN操作日志
            GoodsLog goodsLog = this.setGoodsLog(gdnNo, loginName, logDate, goods);
            goodsLogMapper.insert(goodsLog);
            //添加SN到HIS表
            GoodsHis goodsHis=new GoodsHis();
            BeanUtil.copyNonNull(goods, goodsHis);
            goodsHis.setLogCreateUser(loginName);
            goodsHis.setLogCreateTime(logDate);
            goodsHis.setStatus(GoodsStatusEnum.HAS_CHUKU.code);
            goodsHis.setWhsId(null);
            goodsHis.setLocId(null);
            goodsHis.setModifyTime(new Date());
            goodsHis.setModifyUser(loginName);
            goodsHisMapper.insert(goodsHis);
        }
        //删除GOODS表的条码
        List<Integer> deleteGoodsIds = goodsList.stream().map(t -> t.getGoodsId()).collect(Collectors.toList());
        QueryWrapper<Goods> delectGoodsQueryWrapper=new QueryWrapper<>();
        delectGoodsQueryWrapper.in("GOODS_ID",deleteGoodsIds);
        goodsMapper.delete(delectGoodsQueryWrapper);
        //更新出库主档、明细、货品状态
        deliveryMapper.updateGdnHeader(gdnNo,GdnHeaderStatusEnum.FINISH.code,loginName,new Date());
        List<BigDecimal> gdnDtlIds = gdnDtlGoodsList.stream().map(t -> t.getGdnDtlId()).distinct().collect(Collectors.toList());
        deliveryMapper.updateGdnDtl(gdnDtlIds,GdnDtlStatusEnum.SHIPMENTED.code,loginName,new Date());
        for (DeliveryGoodsResponse deliveryGoods: gdnDtlGoodsList) {
            deliveryMapper.updateGdnGoods(deliveryGoods.getGdnDtlId(),
                    GdnDtlGoodsStatusEnum.OS_SHIP.code,deliveryGoods.getGoodsSn(),loginName,new Date());
        }
        //清除缓存
        this.deleteCache(gdnNo);

        return new Result(true,"交接成功!");
    }


    //获取交接确认主页
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public DeliveryMainResponse searchMainPage(String gdnNo){
        List<DeliveryHeaderResponse> deliveryHeaders = deliveryMapper.selectDeliveryHeader(gdnNo);
        if (CollectionUtil.isEmpty(deliveryHeaders)){
            Shift.fatal("没有找到对应出库单["+gdnNo+"]的信息!");
        }
        DeliveryHeaderResponse deliveryHeader = deliveryHeaders.get(0);
        if (deliveryHeader==null){
            Shift.fatal("没有找到对应出库单["+gdnNo+"]的信息!");
        }
        if (deliveryHeader.getHeaderStatus()==null){
            Shift.fatal("出库单["+gdnNo+"]状态错误");
        }
        if (deliveryHeader.getHeaderStatus().equals(GdnHeaderStatusEnum.CANCEL.code)){
            Shift.fatal("出库单["+gdnNo+"]状态为["+GdnHeaderStatusEnum.CANCEL.enumName+"],不可进行出库交接确认。");
        }
        if (deliveryHeader.getHeaderStatus().equals(GdnHeaderStatusEnum.FINISH.code)){
            Shift.fatal("出库单["+gdnNo+"]状态为["+GdnHeaderStatusEnum.FINISH.enumName+"],不可进行出库交接确认。");
        }
        if (deliveryHeader.getHeaderStatus().equals(GdnHeaderStatusEnum.CLOSE.code)){
            Shift.fatal("出库单["+gdnNo+"]状态为["+GdnHeaderStatusEnum.CLOSE.enumName+"],不可进行出库交接确认。");
        }
        GdnHeaderStatusEnum gdnHeaderStatusEnum = GdnHeaderStatusEnum.getEnumByCode(deliveryHeader.getHeaderStatus());
        if (gdnHeaderStatusEnum!=null){
            deliveryHeader.setHeaderStatusStr(gdnHeaderStatusEnum.enumName);
        }
        if (deliveryHeader.getGdnType()!=null){
            GdnTypeEnum gdnTypeEnum = GdnTypeEnum.getEnumByCode(deliveryHeader.getGdnType());
            if (gdnTypeEnum!=null){
                deliveryHeader.setGdnTypeStr(gdnTypeEnum.enumName);
            }
        }
        //查询主页明细信息
        List<DeliveryDtlResponse> deliveryDtlList = this.searchDtlCommon(gdnNo, deliveryHeader.getGdnHeaderId());
        DeliveryMainResponse result=new DeliveryMainResponse();
        result.setHeader(deliveryHeader);
        result.setDtlList(deliveryDtlList);

        return result;
    }

    //主页面扫描SN后返回明细信息
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public List<DeliveryDtlResponse> scanSnDelivery(String gdnNo,BigDecimal gdnHeaderId,String goodsSn){
        if (goodsSn==null){
            Shift.fatal("请扫描条码!");
        }
        Goods goods = goodsMapper.selectBySn(goodsSn);
        if (goods==null){
            Shift.fatal("没有条码["+goodsSn+"]的信息!");
        }
        if (!goods.getStatus().equals(GoodsStatusEnum.HAS_DOWN.code)){
            Shift.fatal("条码["+goodsSn+"]状态非["+GoodsStatusEnum.HAS_DOWN.enumName+"]，不可出库!");
        }
        //获取扫描的SN信息
        List<DeliveryGoodsResponse> deliveryGoods = deliveryMapper.selectOneDeliveryGoods(gdnHeaderId, goodsSn);
        if (CollectionUtil.isEmpty(deliveryGoods)){
            Shift.fatal("条码["+goodsSn+"]没有在出库单["+gdnNo+"]下!");
        }

        //获取缓存的条码信息
        List<DeliveryGoodsResponse> goodsListCache = this.getGoodsListCache(gdnNo);
        if (!CollectionUtil.isEmpty(goodsListCache)){
            List<String> cacheGoodsSnList = goodsListCache.stream().map(t -> t.getGoodsSn()).collect(Collectors.toList());
            if (cacheGoodsSnList.contains(goodsSn)){
                Shift.fatal("SN["+goodsSn+"]已扫描!");
            }
        }else {
            goodsListCache=new ArrayList<>();
        }
        DeliveryGoodsResponse cacheDeliveryGoods=new DeliveryGoodsResponse();
        cacheDeliveryGoods.setStatusStr(DeliveryScanStatusEnum.YES_SCAN.enumName);
        cacheDeliveryGoods.setDescCn(deliveryGoods.get(0).getDescCn());
        cacheDeliveryGoods.setGoodsSn(goodsSn);
        cacheDeliveryGoods.setSkuCode(deliveryGoods.get(0).getSkuCode());
        cacheDeliveryGoods.setSkuId(deliveryGoods.get(0).getSkuId());
        cacheDeliveryGoods.setQty(goods.getQty());
        goodsListCache.add(cacheDeliveryGoods);
        this.insertUpdateGoodCache(gdnNo,goodsListCache);

        return this.searchDtlCommon(gdnNo,gdnHeaderId);
    }

    //点击明细进入SN详情页
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public List<DeliveryGoodsResponse> searchDeliveryGoods(String gdnNo, BigDecimal gdnHeaderId,BigDecimal skuId){
        if (gdnHeaderId==null){
            Shift.fatal("请扫描正确的出库条码!");
        }
        List<DeliveryGoodsResponse> results=new ArrayList<>();

        //查询返回信息
        List<DeliveryGoodsResponse> datas = deliveryMapper.selectDeliveryGoods(gdnHeaderId, skuId);
        //查询对应发货单明细的条码
        if (CollectionUtil.isEmpty(datas)){
            return null;
        }
        List<String> allGoodsSn = datas.stream().map(t -> t.getGoodsSn()).collect(Collectors.toList());
        List<Goods> allGoodsList = goodsMapper.selectList(new QueryWrapper<Goods>().in("GOODS_SN", allGoodsSn));

        //获取缓存的条码
        List<DeliveryGoodsResponse> goodsListCache = this.getGoodsListCache(gdnNo);

        Map<String, List<DeliveryGoodsResponse>> deliveryMap = datas.stream().collect(Collectors.groupingBy(DeliveryGoodsResponse::getGoodsSn));
        List<String> cacheGoodsSnList = new ArrayList<>();
        if (!CollectionUtil.isEmpty(goodsListCache)){
            cacheGoodsSnList=goodsListCache.stream().map(t -> t.getGoodsSn()).collect(Collectors.toList());
        }
        for (Goods goods : allGoodsList) {
            DeliveryGoodsResponse goodsResponse = deliveryMap.get(goods.getGoodsSn()).get(0);
            DeliveryGoodsResponse deliveryGoodsResponse=new DeliveryGoodsResponse();
            deliveryGoodsResponse.setQty(goods.getQty());
            deliveryGoodsResponse.setSkuId(goodsResponse.getSkuId());
            deliveryGoodsResponse.setSkuCode(goodsResponse.getSkuCode());
            deliveryGoodsResponse.setSkuId(goodsResponse.getSkuId());
            deliveryGoodsResponse.setDescCn(goodsResponse.getDescCn());
            deliveryGoodsResponse.setGoodsSn(goodsResponse.getGoodsSn());
            if (cacheGoodsSnList.contains(goods.getGoodsSn())){
                deliveryGoodsResponse.setStatusStr(DeliveryScanStatusEnum.YES_SCAN.enumName);
            }else {
                deliveryGoodsResponse.setStatusStr(DeliveryScanStatusEnum.NO_SCAN.enumName);
            }
            results.add(deliveryGoodsResponse);
        }


        return results;
    }

    //SN反扫描【POST请求】
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public List<DeliveryGoodsResponse> cancelSn(String gdnNo, BigDecimal gdnHeaderId,
                                                BigDecimal skuId,List<String> cancelSnList){
        if (CollectionUtil.isEmpty(cancelSnList)){
            Shift.fatal("请选择条码提交");
        }
        //获取缓存
        List<DeliveryGoodsResponse> goodsListCache = getGoodsListCache(gdnNo);
        if (CollectionUtil.isEmpty(goodsListCache)){
            Shift.fatal("该发货单下不存在已扫描的条码，无法取消!");
        }
        List<String> cacheGoodsList = goodsListCache.stream().map(t -> t.getGoodsSn()).collect(Collectors.toList());
        for (String goodsSn : cacheGoodsList) {
            if (!cacheGoodsList.contains(goodsSn)){
                Shift.fatal("["+goodsSn+"}未扫描，无法反扫描!");
            }
        }
        List<DeliveryGoodsResponse> insetCacheList=new ArrayList<>();
        for (DeliveryGoodsResponse goodsResponse : goodsListCache) {
            if (!cancelSnList.contains(goodsResponse.getGoodsSn())){
                insetCacheList.add(goodsResponse);
            }
        }
        this.insertUpdateGoodCache(gdnNo,insetCacheList);

        return searchDeliveryGoods(gdnNo,gdnHeaderId,skuId);
    }


    //根据缓存的SN信息计算主页明细的扫描数量
    private List<DeliveryDtlResponse> searchDtlCommon(String gdnNo, BigDecimal gdnHeaderId){
        //先查缓存，缓存中默认扫描数为0
        List<DeliveryDtlResponse> result=new ArrayList<>();
        List<DeliveryDtlResponse> dtlCache =deliveryMapper.selectDeliveryDtl(gdnHeaderId);
        if (CollectionUtil.isEmpty(dtlCache)){
            return dtlCache;
        }
        for (DeliveryDtlResponse dtl : dtlCache) {
            dtl.setScanQtys(BigDecimal.ZERO);
        }
        if (!CollectionUtil.isEmpty(dtlCache)){
            //查询缓存的货品信息
            List<DeliveryGoodsResponse> goodsListCache = this.getGoodsListCache(gdnNo);
            if (CollectionUtil.isEmpty(goodsListCache)) return dtlCache;

            //根据skuId对库存进行分组
            Map<BigDecimal, List<DeliveryGoodsResponse>> collect =
                    goodsListCache.stream().collect(Collectors.groupingBy(DeliveryGoodsResponse::getSkuId));
            for (DeliveryDtlResponse dtl : dtlCache) {
                List<DeliveryGoodsResponse> goodsCollect = collect.get(dtl.getSkuId());
                BigDecimal scanQtys=BigDecimal.ZERO;
                if (!CollectionUtil.isEmpty(goodsCollect)){
                    for (DeliveryGoodsResponse goods : goodsCollect) {
                        if (goods.getQty()!=null){
                            scanQtys=scanQtys.add(goods.getQty());
                        }
                    }
                }
                dtl.setScanQtys(scanQtys);
                result.add(dtl);
            }
        }
        return result;
    }

    //生成入库凭证单头
    private TrsnHeader setTrsnHeader(SimpleGdnHeader header, SimpleGdnDtl dtl,String loginName){
        TrsnHeader result = new TrsnHeader();
        result.setNoteNo(basicSimpleCodeRuleApi.GenerateCode(TRSN_ORDER));
        result.setNoteType(TrsnNoteTypeEnum.OUT_STORAGE.getCode());
        result.setOwner(header.getOwner());
        result.setFactory(header.getFactory());
        result.setWhsId(dtl.getWhsId());
        result.setVendorId(dtl.getVendor());
        result.setFmDoc(header.getGdnNo());
        result.setCreateUser(loginName);
        result.setStatus(TrsnHeaderStatusEnum.CMP.code);
        result.setCreateTime(new Date());

        return result;
    }

    //生成入库凭证明细
    private List<TrsnDtl> setTrsnDtlList(SimpleGdnHeader gdnHeader, List<SimpleGdnDtl> gdnDtlList,
                                         String loginName,TrsnHeader trsnHeader){
        int lineCount=0;
        Date date = new Date();
        List<TrsnDtl> resultList=new ArrayList<>();
        for (SimpleGdnDtl gdnDtl : gdnDtlList) {
            TrsnDtl trsnDtl=new TrsnDtl();
            trsnDtl.setTrsnHeaderId(trsnHeader.getTrsnHeaderId());
            trsnDtl.setNoteNo(trsnHeader.getNoteNo());
            trsnDtl.setNoteLineNo(""+lineCount);
            trsnDtl.setFmDoc(gdnHeader.getGdnNo());
            trsnDtl.setFmDocLine(""+gdnDtl.getGdnLineNo());
            trsnDtl.setInvUpdateFlag(TrsnDtlInvUpdateFlagEnum.OUT.code);
            trsnDtl.setSkuId(gdnDtl.getSkuId());
            trsnDtl.setQty(gdnDtl.getOrderQty());
            trsnDtl.setUnit(gdnDtl.getUnit());
            trsnDtl.setInvAttr(gdnDtl.getInvAttr());
            trsnDtl.setInvType(gdnDtl.getInvType());
            trsnDtl.setQaStatus(gdnDtl.getQaStatus());
            trsnDtl.setLotAttr1(gdnDtl.getLotAttr1());
            trsnDtl.setLotAttr2(gdnDtl.getLotAttr2());
            trsnDtl.setLotAttr3(gdnDtl.getLotAttr3());
            trsnDtl.setLotAttr4(gdnDtl.getLotAttr4());
            trsnDtl.setLotAttr5(gdnDtl.getLotAttr5());
            trsnDtl.setLotAttr6(gdnDtl.getLotAttr6());
            trsnDtl.setLotAttr7(gdnDtl.getLotAttr7());
            trsnDtl.setLotAttr8(gdnDtl.getLotAttr8());
            trsnDtl.setLotAttr9(gdnDtl.getLotAttr9());
            trsnDtl.setLotAttr10(gdnDtl.getLotAttr10());
            trsnDtl.setLotAttr11(gdnDtl.getLotAttr11());
            trsnDtl.setLotAttr12(gdnDtl.getLotAttr12());
            trsnDtl.setStatus(TrsnDtlStatusEnum.CMP.code);
            trsnDtl.setCreateUser(loginName);
            trsnDtl.setCreateTime(date);
            resultList.add(trsnDtl);
            lineCount++;
        }
        return resultList;
    }

    //生成库存信息
    private UpdateInventoryInputDto setInventoryInputDto(
            Goods goods,String loginName){
        UpdateInventoryInputDto inventoryInputDto = new UpdateInventoryInputDto();
        inventoryInputDto.setWhsId(goods.getWhsId());
        inventoryInputDto.setLocId(goods.getLocId());
        inventoryInputDto.setOwner(goods.getOwner());
        inventoryInputDto.setSkuId(goods.getSkuId());
        inventoryInputDto.setFactory(goods.getFactory());
        inventoryInputDto.setVendorId(goods.getVendorId());
        inventoryInputDto.setLotNo(goods.getLotno());
        inventoryInputDto.setInvAttr(goods.getInvAttr());
        inventoryInputDto.setQaStatus(goods.getQaStatus());
        inventoryInputDto.setOperator(loginName);
        inventoryInputDto.setQty(BigDecimal.ZERO.subtract(goods.getQty()));
        inventoryInputDto.setAlocQty(goods.getQty().negate());
        return inventoryInputDto;

    }

    //生成操作日志
    private GoodsLog setGoodsLog(String gdnNo,String loginName,Date logDate,Goods goods){
        GoodsLog goodsLog = new GoodsLog();
        goodsLog.setGoodsSn(goods.getGoodsSn());
        goodsLog.setOpCode(OpCodeEnum.SHIPPED.getCode());
        goodsLog.setReason("出库确认,出库单号"+gdnNo);
        String goodsJson="未更新的:" + JSON.toJSONString(goods)+ ",更新的:{条码"+goods.getGoodsSn()+"删除移动到HIS表}";
        goodsLog.setUpdateContent(goodsJson);
        goodsLog.setOperator(loginName);
        goodsLog.setCreateUser(loginName);
        goodsLog.setCreateTime(logDate);
        goodsLog.setModifyUser(loginName);
        goodsLog.setModifyTime(logDate);
        return goodsLog;
    }


    //根据gdnNo+SN为key查询缓存
    public List<DeliveryGoodsResponse> getGoodsListCache(String gdnNo){
        String key=gdnNo;
        log.info("key:{}", key);
        List<DeliveryGoodsResponse> results=(List<DeliveryGoodsResponse>) RedisUtil.get(key);
        return results;
    }

    //根据gdnNo+SN为key添加/更新缓存
    public void insertUpdateGoodCache(String gdnNo,List<DeliveryGoodsResponse> request){
        String key=gdnNo;
        RedisUtil.set(key,request);
    }

    //根据gdnNo+flag为key删除缓存【flag为DTL/SN】
    public void deleteCache(String gdnNo){
        String key=gdnNo;
        RedisUtil.delete(key);
    }

}
*/
